# Various functions that are not methods of any class in the Reporting package
# 
###############################################################################

#' Replaces special characters in a string with the proper html escape sequences
#' 
#' Returns a copy of its argument in which special characters are replaced by their html escape sequences.
#' @param text The character string that will be escaped.
#' @return The escaped version of the character string. 
escapeHtml <- function(text)
{
    if (is.null(text))
        return(NULL)
    escapePairs <- matrix(data=c("\"","&quot;",
                                 '&',"&amp;",
                                 '<',"&lt;",
                                 '>',"&gt;"), byrow=TRUE, ncol=2  ) # TODO complete the list of characters that need escaping
    escapedText <- vector()
    for ( char in strsplit(x=text, split="")[[1]] )
    {
        if (char %in% escapePairs[,1])
            char <- escapePairs[which(char==escapePairs[,1]) ,2]
        escapedText <- c(escapedText,char)
    }
    return(paste(escapedText, collapse=""))
}

